package com.niit.project.dao.impl;

import com.niit.project.dao.ReportDao;
import com.niit.project.entity.Report;
import com.niit.project.utils.Dbutils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class ReportDaoImpl implements ReportDao {
    QueryRunner queryRunner = new QueryRunner();
    @Override
    public int insert(String report) {
        try {
            int result = queryRunner.update(Dbutils.getConnection(),"insert into report(content) values(?)",report);
            return result;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<Report> select() {
        try {
            List<Report> report = queryRunner.query(Dbutils.getConnection(),"select content from report",new BeanListHandler<Report>(Report.class));
            return report;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
